<template>
  <el-drawer v-model="drawerVisible" :destroy-on-close="true" size="450px" :title="`${drawerProps.title}检测模拟量`">
    <el-form
      ref="ruleFormRef"
      label-width="100px"
      label-suffix=" :"
      :disabled="drawerProps.isView"
      :model="drawerProps.row"
      :hide-required-asterisk="drawerProps.isView"
    >

      <el-form-item label="部位名称" prop="positionName">
        <el-input v-model.trim="drawerProps.row!.positionName" placeholder="请填写部位名称" clearable></el-input>
      </el-form-item>

      <el-form-item label="部位序号" prop="positionNumber">
        <el-input v-model="drawerProps.row!.positionNumber" placeholder="请填写部位序号" clearable></el-input>
      </el-form-item>

      <el-form-item label="解析标志" prop="parsingFlag">
        <el-input v-model="drawerProps.row!.parsingFlag" placeholder="请填写解析标志" clearable></el-input>
      </el-form-item>

      <el-form-item label="标识列" prop="identifierColumn">
        <el-input v-model="drawerProps.row!.identifierColumn" placeholder="请填写标识列" clearable></el-input>
      </el-form-item>

      <el-form-item label="采集机编号" prop="collectionMachineNumber">
        <el-input v-model="drawerProps.row!.collectionMachineNumber" placeholder="请填写采集机编号" clearable></el-input>
      </el-form-item>

      <el-form-item label="AD号" prop="adNumber">
        <el-input v-model="drawerProps.row!.adNumber" placeholder="请填写AD号" clearable></el-input>
      </el-form-item>

      <el-form-item label="显示序号" prop="displaySequence">
        <el-input v-model="drawerProps.row!.displaySequence" placeholder="请填写显示序号" clearable></el-input>
      </el-form-item>

      <el-form-item label="AD最小值" prop="adMin">
        <el-input v-model="drawerProps.row!.adMin" placeholder="请填写AD最小值" clearable></el-input>
      </el-form-item>

      <el-form-item label="AD最大值" prop="adMax">
        <el-input v-model="drawerProps.row!.adMax" placeholder="请填写AD最大值" clearable></el-input>
      </el-form-item>

      <el-form-item label="报警下限" prop="alarmLowerLimit">
        <el-input v-model="drawerProps.row!.alarmLowerLimit" placeholder="请填写报警下限" clearable></el-input>
      </el-form-item>

      <el-form-item label="报警上限" prop="alarmUpperLimit">
        <el-input v-model="drawerProps.row!.alarmUpperLimit" placeholder="请填写报警上限" clearable></el-input>
      </el-form-item>

      <el-form-item label="分路最低值" prop="roadMinimum">
        <el-input v-model="drawerProps.row!.roadMinimum" placeholder="请填写分路最低值" clearable></el-input>
      </el-form-item>

      <el-form-item label="计量单位" prop="measurementUnit">
        <el-input v-model="drawerProps.row!.measurementUnit" placeholder="请填写计量单位" clearable></el-input>
      </el-form-item>

      <el-form-item label="系数" prop="coefficient">
        <el-input v-model="drawerProps.row!.coefficient" placeholder="请填写系数" clearable></el-input>
      </el-form-item>

      <el-form-item label="INI文件名" prop="iniFileName">
        <el-input v-model="drawerProps.row!.iniFileName" placeholder="请填写INI文件名" clearable></el-input>
      </el-form-item>

      <el-form-item label="采集板地址" prop="collectionBoardAddress">
        <el-input v-model="drawerProps.row!.collectionBoardAddress" placeholder="请填写采集板地址" clearable></el-input>
      </el-form-item>

      <el-form-item label="高频模拟量周期" prop="highFrequencyAnalogPeriod">
        <el-input v-model="drawerProps.row!.highFrequencyAnalogPeriod" placeholder="请填写高频模拟量周期" clearable></el-input>
      </el-form-item>

      <el-form-item label="道岔曲线最高点切割线" prop="turnoutCurveHighestCuttingLine">
        <el-input v-model="drawerProps.row!.turnoutCurveHighestCuttingLine" placeholder="请填写道岔曲线最高点切割线" clearable></el-input>
      </el-form-item>

      <el-form-item label="道岔曲线波峰个数" prop="turnoutCurvePeakNumber">
        <el-input v-model="drawerProps.row!.turnoutCurvePeakNumber" placeholder="请填写道岔曲线波峰个数" clearable></el-input>
      </el-form-item>

      <el-form-item label="一级报警上限" prop="levelOneAlarmUpperLimit">
        <el-input v-model="drawerProps.row!.levelOneAlarmUpperLimit" placeholder="请填写一级报警上限" clearable></el-input>
      </el-form-item>

      <el-form-item label="一级报警下限" prop="levelOneAlarmLowerLimit">
        <el-input v-model="drawerProps.row!.levelOneAlarmLowerLimit" placeholder="请填写一级报警下限" clearable></el-input>
      </el-form-item>

      <el-form-item label="一级报警分路限" prop="levelOneAlarmRoadLimit">
        <el-input v-model="drawerProps.row!.levelOneAlarmRoadLimit" placeholder="请填写一级报警分路限" clearable></el-input>
      </el-form-item>


    </el-form>
    <template #footer>
      <el-button @click="drawerVisible = false">取消</el-button>
      <el-button v-show="!drawerProps.isView" type="primary" @click="handleSubmit">确定</el-button>
    </template>
  </el-drawer>
</template>

<script setup lang="ts" name="DeviceInformationDrawer">
import { ref, reactive } from "vue";
import { entrain } from "@/utils/dict";
import { ElMessage, FormInstance } from "element-plus";
import {Dataset, DeviceInformation, Model, MonitioringProject} from "@/api/interface";
import UploadImg from "@/components/Upload/Img.vue";
import UploadImgs from "@/components/Upload/Imgs.vue";
import { getDModelList } from "@/api/modules/new2";



interface DrawerProps {
  title: string;
  isView: boolean;
  row: Partial<DeviceInformation.ResDeviceInformationList>;
  api?: (params: any) => Promise<any>;
  getTableList?: () => void;
  did: number
}

const drawerVisible = ref(false);
const drawerProps = ref<DrawerProps>({
  isView: false,
  title: "",
  row: {},
  did: null
});

// 接收父组件传过来的参数
const acceptParams = (params: DrawerProps) => {

  drawerProps.value = params;
  drawerVisible.value = true;
};

// 提交数据（新增/编辑）
const ruleFormRef = ref<FormInstance>();
const  handleSubmit = () => {
  try {
    const deviceInformationEntity = { ...drawerProps.value.row, did: drawerProps.value.did };
    drawerProps.value.api!(deviceInformationEntity);
    ElMessage.success({ message: `${drawerProps.value.title}设备模拟量成功！` });
    drawerProps.value.getTableList!();
    drawerVisible.value = false;
  } catch (error) {
    console.log(error);
  }


};

defineExpose({
  acceptParams
});
</script>
